//
//  MYComposeTool.m
//  奇闻
//
//  Created by 似水灵修 on 14-12-1.
//  Copyright (c) 2014年 MingYueGuCheng. All rights reserved.
//

#import "MYComposeTool.h"
#import "MJExtension.h"
#import "MYComposeParam.h"
#import "MYHttpTool.h"
#import "MYUploadParam.h"
@implementation MYComposeTool
+ (void)composeWithStatus:(id)status success:(void (^)())success failure:(void (^)(NSError *))failure
{
    MYComposeParam *param = [MYComposeParam param];
    param.status = status;
    [MYHttpTool POST:@"https://api.weibo.com/2/statuses/update.json" parameters:param.keyValues success:^(id responseObject) {
        if (success) {
            success();
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}
+ (void)composeWithImage:(UIImage *)image status:(id)status success:(void (^)())success failure:(void (^)(NSError *))failure
{
    MYComposeParam *param = [MYComposeParam param];
    param.status = status;
    MYUploadParam *upParam = [[MYUploadParam alloc] init];
    upParam.data = UIImagePNGRepresentation(image);
    upParam.paramName = @"pic";
    upParam.fileName = @"image.png";
    upParam.mimeType = @"image/png";
    [MYHttpTool upload:@"https://upload.api.weibo.com/2/statuses/upload.json" parameters:param.keyValues uploadParam:upParam success:^(id responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}
@end
